#!/bin/bash

screen -ls | grep ^No && screen -dm
[ -z $STY ] && mycmd="screen -X" || mycmd=""

pxylst=`netstat -tln | grep -o "127.0.0.1:50\w\w" | sort`
[ -z "$pxylst" ] && echo "No proxy found" && exit 1

echo "$pxylst" | while read pxy; do
  echo -n .
  #$mycmd screen -t ${pxy##*:} tmp.sh ${pxy##*:}
  $mycmd screen -t ${pxy##*:} mydl2.sh $pxy
  sleep 0.1
done
echo Done

#at most maxnum mydl.sh, and start proxy from offset
#maxnum=$1
#offset=$2
#netstat -tln | grep -o "127.0.0.1:50\w\w" |sort > proxy.lst
#echo pxynum `cat proxy.lst|wc -l`
#num=$((`cat rsfile.lst | wc -l`))
#echo -n filenum $num
#sed ${1:-1},+$num\!d proxy.lst | while read pxy; do
